<template>
  <!-- 基于 Element UI 新增和修改弹窗 -->
    <a-drawer
            :title="!dataForm.cid ? '添加' : '修改'"
            :visible="visible"
            @close="cancel"
            :body-style="{ paddingBottom: '80px' }"
            :width="750"
    >
    <!-- 新增和创建表单表单 -->
    <el-form :model="dataForm" :rules="dataRule"  v-loading="loading" ref="dataForm" @keyup.enter.native="dataSubmit()" label-width="80px" style="padding: 0px 10px;margin: 0px 10px">
    <el-form-item label="生成的随机id" >
      <el-input v-model="dataForm.cuuid" placeholder="生成的随机id" size="small"></el-input>
    </el-form-item>
    <el-form-item label="内容" >
      <el-input v-model="dataForm.content" placeholder="内容" size="small"></el-input>
    </el-form-item>
    <el-form-item label="图片路径" >
      <el-input v-model="dataForm.pictureaddr" placeholder="图片路径" size="small"></el-input>
    </el-form-item>
    <el-form-item label="发布时间" >
      <el-input v-model="dataForm.creationtime" placeholder="发布时间" size="small"></el-input>
    </el-form-item>
    <el-form-item label="动态发布位置" >
      <el-input v-model="dataForm.creationaddr" placeholder="动态发布位置" size="small"></el-input>
    </el-form-item>
    <el-form-item label="发布经度" >
      <el-input v-model="dataForm.longitude" placeholder="发布经度" size="small"></el-input>
    </el-form-item>
    <el-form-item label="发布纬度" >
      <el-input v-model="dataForm.latitude" placeholder="发布纬度" size="small"></el-input>
    </el-form-item>
    <el-form-item label="号码绑定是谁发的动态" >
      <el-input v-model="dataForm.cphone" placeholder="号码绑定是谁发的动态" size="small"></el-input>
    </el-form-item>
    <el-form-item label="用户头像" >
      <el-input v-model="dataForm.userimg" placeholder="用户头像" size="small"></el-input>
    </el-form-item>
    <el-form-item label="用户名" >
      <el-input v-model="dataForm.userniname" placeholder="用户名" size="small"></el-input>
    </el-form-item>
    <el-form-item label="1男、2女" >
      <el-input v-model="dataForm.gender" placeholder="1男、2女" size="small"></el-input>
    </el-form-item>
    <el-form-item label="年龄" >
      <el-input v-model="dataForm.age" placeholder="年龄" size="small"></el-input>
    </el-form-item>
    <el-form-item label="审核-- 0:通过  1:不通过 3:被举报" >
      <el-input v-model="dataForm.audit" placeholder="审核-- 0:通过  1:不通过 3:被举报" size="small"></el-input>
    </el-form-item>
    <el-form-item label="打招呼使用" >
      <el-input v-model="dataForm.uid" placeholder="打招呼使用" size="small"></el-input>
    </el-form-item>
    <el-form-item label="用户ID" >
      <el-input v-model="dataForm.userid" placeholder="用户ID" size="small"></el-input>
    </el-form-item>
    <el-form-item label="举报动态理由" >
      <el-input v-model="dataForm.reportdynamicdetails" placeholder="举报动态理由" size="small"></el-input>
    </el-form-item>
    <el-form-item label="" >
      <el-input v-model="dataForm.topsort" placeholder="" size="small"></el-input>
    </el-form-item>
    <el-form-item label="" >
      <el-input v-model="dataForm.viewstatus" placeholder="" size="small"></el-input>
    </el-form-item>
    <el-form-item label="" >
      <el-input v-model="dataForm.replystatus" placeholder="" size="small"></el-input>
    </el-form-item>
    </el-form>
        <div :style="{position: 'absolute',right: 0,bottom: 0,width: '100%', borderTop: '1px solid #e9e9e9',padding: '10px 16px',background: '#fff',textAlign: 'right',zIndex: 1,}">
            <el-button @click="cancel()" :style="{ marginRight: '8px' }">取消</el-button>
            <el-button type="primary" @click="submit()">确定</el-button>
        </div>
  </a-drawer>
</template>

<script>
    import api from '@/api/api'
    export default {
    components: {
    },
    data () {
      return {
        visible: false,
        loading:false,
        dataForm: {
          cid: 0,
          cuuid: '' ,
          content: '' ,
          pictureaddr: '' ,
          creationtime: '' ,
          creationaddr: '' ,
          longitude: '' ,
          latitude: '' ,
          cphone: '' ,
          userimg: '' ,
          userniname: '' ,
          gender: '' ,
          age: '' ,
          audit: '' ,
          uid: '' ,
          userid: '' ,
          reportdynamicdetails: '' ,
          topsort: '' ,
          viewstatus: '' ,
          replystatus: ''
        },
        dataRule: {
          cuuid: [
            { required: true, message: '生成的随机id  为必填项', trigger: 'blur' }
          ],
          content: [
            { required: true, message: '内容  为必填项', trigger: 'blur' }
          ],
          pictureaddr: [
            { required: true, message: '图片路径  为必填项', trigger: 'blur' }
          ],
          creationtime: [
            { required: true, message: '发布时间  为必填项', trigger: 'blur' }
          ],
          creationaddr: [
            { required: true, message: '动态发布位置  为必填项', trigger: 'blur' }
          ],
          longitude: [
            { required: true, message: '发布经度  为必填项', trigger: 'blur' }
          ],
          latitude: [
            { required: true, message: '发布纬度  为必填项', trigger: 'blur' }
          ],
          cphone: [
            { required: true, message: '号码绑定是谁发的动态  为必填项', trigger: 'blur' }
          ],
          userimg: [
            { required: true, message: '用户头像  为必填项', trigger: 'blur' }
          ],
          userniname: [
            { required: true, message: '用户名  为必填项', trigger: 'blur' }
          ],
          gender: [
            { required: true, message: '1男、2女  为必填项', trigger: 'blur' }
          ],
          age: [
            { required: true, message: '年龄  为必填项', trigger: 'blur' }
          ],
          audit: [
            { required: true, message: '审核-- 0:通过  1:不通过 3:被举报  为必填项', trigger: 'blur' }
          ],
          uid: [
            { required: true, message: '打招呼使用  为必填项', trigger: 'blur' }
          ],
          userid: [
            { required: true, message: '用户ID  为必填项', trigger: 'blur' }
          ],
          reportdynamicdetails: [
            { required: true, message: '举报动态理由  为必填项', trigger: 'blur' }
          ],
          topsort: [
            { required: true, message: '  为必填项', trigger: 'blur' }
          ],
          viewstatus: [
            { required: true, message: '  为必填项', trigger: 'blur' }
          ],
          replystatus: [
            { required: true, message: '  为必填项', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) { // 初始化表单验证规则
        this.dataForm.cid = id || undefined
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.cid){
              this.loading = true
                api.post('rest/vabc/friendsCircle/info',{cid:this.dataForm.cid}).then(res => {
                this.dataForm = res;
            }).finally(() => {
                this.loading = false
            });
          }
        })
      },
      // 表单数据提交
      submit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            let postData=Object.assign({},this.dataForm)
            if (!this.dataForm.cid){
                postData.cid==undefined
                api.post('rest/vabc/friendsCircle/save',postData).then(res =>{
                    this.$message.success("创建成功")
                    this.reset()
                    this.visible = false
                    this.$parent.getDataList()
                }).finally(() => {
                    this.loading = false
                });
            }else{
                api.post('rest/vabc/friendsCircle/update',postData).then(res =>{
                    this.$message.success("保存成功")
                    this.reset()
                    this.visible = false
                    this.$parent.getDataList()
                }).finally(() => {
                    this.loading = false
                });
            }
          }
        })
      },
     cancel(){
        this.visible = false
        this.reset()
    },
    reset(){
        this.$refs.dataForm.resetFields()
        this.$data.dataForm=JSON.parse(JSON.stringify(this.$options.data().dataForm))
        //图片回写
        //this.$refs["childData"].fileList=[]
    }
    }
  }
</script>
